<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>AdminLTE 3 | 登录</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <link rel="stylesheet" href="/adminlte/plugins/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="/adminlte/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
    <link rel="stylesheet" href="/adminlte/plugins/toastr/toastr.min.css">
    <link rel="stylesheet" href="/adminlte/css/adminlte.min.css">
</head>

<body class="hold-transition login-page">
    <div class="login-box">
        <div class="login-logo"><a href="#"><b>Admin</b>LET</a></div>
        <div class="card">
            <div class="card-body login-card-body">
                <p class="login-box-msg">登录账号，开始管理工作</p>
                <form method="post">
                    <div class="input-group mb-3">
                        <input type="text" class="form-control" name="username" placeholder="账号">
                        <div class="input-group-append">
                            <div class="input-group-text"><span class="fas fa-user-astronaut"></span></div>
                        </div>
                    </div>
                    <div class="input-group mb-3">
                        <input type="password" class="form-control" name="password" placeholder="密码">
                        <div class="input-group-append">
                            <div class="input-group-text"><span class="fas fa-lock"></span></div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-8">
                            <div class="icheck-primary">
                                <input type="checkbox" id="remember" name="remember">
                                <label for="remember">记住登录</label>
                            </div>
                        </div>
                        <div class="col-4">
                            {%if param.redirect%}
                            <input type="hidden" name="redirect" value="{{param.redirect}}">
                            {%endif%}
                            {{ csrf()|raw }}
                            <button type="submit" class="btn btn-primary btn-block">登录</button>
                        </div>
                    </div>
                </form>

                <p class="mt-3 mb-1">如忘记密码，请联系管理员，以重置密码</p>
            </div>
        </div>
    </div>

    <script src="/adminlte/plugins/jquery/jquery.min.js"></script>
    <script src="/adminlte/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="/adminlte/plugins/toastr/toastr.min.js"></script>
    <script src="/adminlte/js/adminlte.min.js"></script>
    <script>
        $(function () {
            $('form').submit(function (e) {
                $('form button[type="submit"]').addClass('disabled');
                e.preventDefault();
                $.ajax({
                    type: 'POST',
                    data: $('form').serialize(),
                    success: function (res) {
                        _msg = ('msg' in res) ? res.msg : '未知错误';
                        if (!('code' in res) || res.code != 0 || !('data' in res) || !('url' in res.data)) {
                            toastr.error(_msg, '', {
                                progressBar: true,
                                positionClass: 'toast-top-center',
                                timeOut: 3000
                            });
                            setTimeout(() => {
                                window.location.reload();
                            }, 4000);
                        } else {
                            toastr.success('登录成功', '', {
                                progressBar: true,
                                positionClass: 'toast-top-center',
                                timeOut: 2000
                            });

                            setTimeout(() => {
                                window.location.href = res.data.url;
                            }, 3000);
                        }
                    }, error: function (xhr) {
                        toastr.error('刷新页面重试', '', {
                            progressBar: true,
                            positionClass: 'toast-top-center',
                            timeOut: 3000
                        });
                        setTimeout(() => {
                            window.location.reload();
                        }, 4000);
                    }
                });
            });
        });
    </script>
</body>

</html>